package com.wuxinwudai.android.util;

/**
 * ArrayUtils 类归功数组工具功能
 * @author 吾心无待 于2016年03月02日
 */
public class ArrayUtils {
    //region 数组连接

    /**
     * 数组连接
     * @param first 数组一
     * @param second 数组二
     * @return 新数组
     */
    public static byte[] join(byte[] first, byte[] second) {
        byte[] result = new byte[first.length + second.length];
        int i = 0, j = 0;
        for (; i < first.length; i++) {
            result[i] = first[i];
        }
        for (; i < result.length; i++) {
            result[i] = second[j++];
        }
        return result;
    }
    /**
     * 数组连接
     * @param first 数组一
     * @param second 数组二
     * @return 新数组
     */
    public static float[] join(float[] first, float[] second) {
        float[] result = new float[first.length + second.length];
        int i = 0, j = 0;
        for (; i < first.length; i++) {
            result[i] = first[i];
        }
        for (; i < result.length; i++) {
            result[i] = second[j++];
        }
        return result;
    }
    /**
     * 数组连接
     * @param first 数组一
     * @param second 数组二
     * @return 新数组
     */
    public static int[] join(int[] first, int[] second) {
        int[] result = new int[first.length + second.length];
        int i = 0, j = 0;
        for (; i < first.length; i++) {
            result[i] = first[i];
        }
        for (; i < result.length; i++) {
            result[i] = second[j++];
        }
        return result;
    }
    /**
     * 数组连接
     * @param first 数组一
     * @param second 数组二
     * @return 新数组
     */
    public static double[] join(double[] first, double[] second) {
        double[] result = new double[first.length + second.length];
        int i = 0, j = 0;
        for (; i < first.length; i++) {
            result[i] = first[i];
        }
        for (; i < result.length; i++) {
            result[i] = second[j++];
        }
        return result;
    }
    /**
     * 数组连接
     * @param first 数组一
     * @param second 数组二
     * @return 新数组
     */
    public static long[] join(long[] first, long[] second) {
        long[] result = new long[first.length + second.length];
        int i = 0, j = 0;
        for (; i < first.length; i++) {
            result[i] = first[i];
        }
        for (; i < result.length; i++) {
            result[i] = second[j++];
        }
        return result;
    }
    /**
     * 数组连接
     * @param first 数组一
     * @param second 数组二
     * @return 新数组
     */
    public static boolean[] join(boolean[] first, boolean[] second) {
        boolean[] result = new boolean[first.length + second.length];
        int i = 0, j = 0;
        for (; i < first.length; i++) {
            result[i] = first[i];
        }
        for (; i < result.length; i++) {
            result[i] = second[j++];
        }
        return result;
    }
    /**
     * 数组连接
     * @param first 数组一
     * @param second 数组二
     * @return 新数组
     */
    public static String[] join(String[] first, String[] second) {
        String[] result = new String[first.length + second.length];
        int i = 0, j = 0;
        for (; i < first.length; i++) {
            result[i] = first[i];
        }
        for (; i < result.length; i++) {
            result[i] = second[j++];
        }
        return result;
    }
    /**
     * 数组连接
     * @param first 数组一
     * @param second 数组二
     * @return 新数组
     */
    public static char[] join(char[] first, char[] second) {
        char[] result = new char[first.length + second.length];
        int i = 0, j = 0;
        for (; i < first.length; i++) {
            result[i] = first[i];
        }
        for (; i < result.length; i++) {
            result[i] = second[j++];
        }
        return result;
    }
    /**
     * 数组连接
     * @param first 数组一
     * @param second 数组二
     * @return 新数组
     */
    public static  Object[] join(Object[] first, Object[] second) {
        Object[] result = new Object[first.length + second.length];
        int i = 0, j = 0;
        for (; i < first.length; i++) {
            result[i] = first[i];
        }
        for (; i < result.length; i++) {
            result[i] = second[j++];
        }
        return result;
    }

    /**
     * 在数组后面添加一个数据，并返回新数组
     * @param arr 原数组
     * @param obj 新对象
     * @return 新数组
     */
    public static Object[] append(Object[] arr,Object obj){
        Object[] result = new Object[arr.length+1];
        int i = 0;
        for (;i < arr.length;i++){
            result[i] = arr[i];
        }
        result[i] = obj;
        return result;
    }

    /**
     * 删除数组的第一个元素
     * @param arr 数组
     * @return 新数组
     */
    public static Object[] shift(Object[] arr){
        Object[] result = new Object[arr.length-1];
        int i = 0;
        for (;i < result.length;i++){
            result[i] = arr[i+1];
        }
        return result;
    }

    /**
     * 在数组最前方插入数据
     * @param obj 对象
     * @param arr 数组
     * @return 新数组
     */
    public static Object[] unshift(Object obj,Object[] arr){
        Object[] result = new Object[arr.length+1];
        int i = 1;
        for (;i < arr.length;i++){
            result[i] = arr[i];
        }
        result[0] = obj;
        return result;
    }
    //endregion
}
